using System.Collections.Generic;
using DMS.BEs;
using DMS.Filters;
using NHibernate;
using NHibernate.Criterion;

namespace DMS.DAOs.NH
{
    public class CustomerDAO : GenericDAO<Customer>, ICustomerDAO
    {
        public CustomerDAO(ISessionFactory sessionFactory)
            : base(sessionFactory)
        { }

        public IList<Customer> GetByFilter(CustomerFilter filter)
        {
            ICriteria query = Session.CreateCriteria<Customer>();

            if (!string.IsNullOrEmpty(filter.Country))
                query.Add(Expression.Eq("Country", filter.Country));
            if (!string.IsNullOrEmpty(filter.State))
                query.Add(Expression.Eq("State", filter.State));
            if (!string.IsNullOrEmpty(filter.City))
                query.Add(Expression.Eq("City", filter.City));
			if (!string.IsNullOrEmpty(filter.FirstName))
				query.Add(Expression.Eq("FirstName", filter.FirstName));
			if (!string.IsNullOrEmpty(filter.LastName))
				query.Add(Expression.Eq("LastName", filter.LastName));

            return query.List<Customer>();
        }
    }
}